10 REM Real-entry matrix inversion (Pan-Reif method)
20 REM Program by Thomas E. Phipps, Jr.
30 REM Ref= Proc. 17th Annual ACM Sympos. on Theory
40 REM of Computing, Providence, RI, May 1985
50 REM Random-entry matrices, single precision
60 REM Quartic modification of Newton's iteration
70 INPUT "Run number = ";RN
80 REM N data is in line 640, D1 data in line 660
90 READ N, D1:RANDOMIZE RN:OPTION BASE 1
100 REM Can optionally insert DEFDBL A,B,E,X instruction here
110 REM A is the matrix to invert, B is the approximate inverse of A, E is the error matrix for the inverse, and X is a temporary storage matrix as explained in the BYTE article.
120 DIM A(N,N),B(N,N),E(N,N),X(N,N)
130 REM Generate random-entry A-matrix. For real data, replace 140 by an INPUT statement and input normalized data (each element of A is divided by the largest element, L). Delete line 150. B and D1 must be multiplied by L later.
140 FOR I=1 TO N:FOR J=1 TO N:A(I,J)=RND(1):NEXT :NEXT
150 FOR I=1 TO N:FOR J=1 TO N:IF RND(1)<.5 THEN A(I,J)=-A(I,J)
160 NEXT :NEXT
170 CLS:TIME$="00" 'Start clock
180 REM Eval. t by Pan-Reif eq 8 in BYTE article
190 FOR I=1 TO N:R0=0:S0=0:FOR J=1 TO N
200 R0=R0+ABS(A(I,J)):S0=S0+ABS(A(J,I)):NEXT J
210 X(1,I)=R0:E(1,I)=S0:NEXT I:T1=0:T2=0
220 FOR I=1 TO N:IF X(1,I)>T1 THEN T1=X(1,I)
230 IF E(1,I)>T2 THEN T2=E(1,I)
240 NEXT I:T=1/(T1*T2)
250 REM Eval. initial B-matrix
260 FOR I=1 TO N:FOR J=1 TO N:B(I,J)=T*A(J,I):NEXT :NEXT :H=0